package com.potenza.training.reply.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class ElasticSearchConfig {

    @Value("${pinxixi.elasticsearch.host}")
    private String host;

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        String[] split = host.split(":");
        //1.链接rest接口
        HttpHost httpHost = new HttpHost(split[0],Integer.parseInt(split[1]),"http");
        RestClientBuilder builder = RestClient.builder(httpHost);//res构造器
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);//高级客户端对象

        return restHighLevelClient;
    }
}
